package commRedisTag

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commRedis"
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/Json"
	"strconv"
)

type redisTagReader struct {
}

func (e *redisTagReader) readTagsSync() (int64, error) {
	str, err := commRedis.Client.Get("fox.edge.tags.sync").Result()
	if err != nil {
		return -1, err
	}

	return strconv.ParseInt(str, 10, 64)
}

func (e *redisTagReader) readTags() (map[string]interface{}, error) {
	datas, err := commRedis.Client.HGetAll("fox.edge.tags.data").Result()
	if err != nil {
		return nil, err
	}

	// 填写新数据
	result := make(map[string]interface{})
	for k, v := range datas {
		value := Json.BuildMap(v)
		if value == nil {
			continue
		}

		result[k] = value
	}

	return result, err
}
